<!DOCTYPE html>
<html>

<head>
  <meta charset="utf-8">
  <meta name="renderer" content="webkit|ie-comp|ie-stand">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <meta http-equiv="Cache-Control" content="no-siteapp" />
  <title>客户端</title>
  <script src="../../../static/kaige/js/szload.js"></script>
</head>

<body>
  <div class="kaige-body">
    <table class="layui-table" id="pageTable" lay-filter="pageTable" lay-size="sm"></table>
    <input type="hidden" name="keywordsCache" value="{}" />
  </div>

  <script>
    load_init_js(function () {
      layui.config({
        base: szoapcpath + '/static/kaige/layuiextend/'
      }).use(['element', 'table', 'form', 'layer', 'kaige'], function () {
        var element = layui.element,
          layer = layui.layer,
          table = layui.table,
          form = layui.form,
          kaige = layui.kaige
        $ = layui.$;
        form.render();

        kaige.table({
          elem: '#pageTable',
          url: "/sys.client/index",
          id: 'pageTable',
          toolbar: '#dtoolbar',
          defaultToolbar: ['filter'],
          cols: [[
            {
              field: 'type', width: 90, title: '类型', align: 'center', templet: function (d) {
                return d.type == 2 ? '远程' : '本地';
              }
            },
            { field: 'app_id', width: 220, title: '应用id', align: 'center' },
            { field: 'app_salt', width: 300, title: '应用签名盐值', align: 'center' },
            { field: 'name', width: 200, title: '应用名称', align: 'center' },
            { field: 'reg_ip', width: 120, title: '服务器IP', align: 'center' },
            { field: 'last_time', width: 160, title: '最后登录时间', align: 'center' },
            { field: 'last_ip', width: 120, title: '最后登录IP', align: 'center' },
            { field: 'desc', width: 120, title: '备注', align: 'center', hide: true },
            { field: 'status', width: 100, title: '状态', align: 'center', templet: function (d) { return statusTd(d) } },
            { field: 'create_time', width: 160, title: '创建时间', align: 'center', hide: true },
            { field: 'update_time', width: 160, title: '更新时间', align: 'center', hide: true },
            { field: 'id', title: '操作', toolbar: '#dtrbar', align: 'center', width: 150, fixed: 'right' }
          ]]
        });

        function statusTd(d) {
          switch (d.status) {
            case 1:
              return '<span class="layui-badge layui-bg-green">启用</span>';
              break;
            case 2:
              return '<span class="layui-badge layui-bg-blank">禁用</span>';
              break;
          }
        }

        //列表-监听表头工具栏事件dtoolbar
        table.on('toolbar(pageTable)', function (obj) {
          switch (obj.event) {
            case 'btn-add':
              btnadd();
              break;
          }
        });

        //列表-监听单元格行工具事件dtrbar
        table.on('tool(pageTable)', function (obj) {
          var that = this;
          var data = obj.data;
          switch (obj.event) {
            case 'edit':
              baredit(data);
              break;
            case 'del':
              bardel(data);
              break;
          }
        });

        //添加
        function btnadd() {
          kaige.form({
            url: "/sys.client/add",
            data: {},
            id: 'kaige',
            area: ['750px', '450px'],
            title: '<i class="layui-icon layui-icon-add-circle"></i> 添加 - 客户端',
            tablelayid: 'pageTable',
            overflow: false,
            encode: 1,
            callbefore: function (layero, index) {
              $('#random_app_id').on('click', function (e) {
                $('input[name=app_id]').val(randomString(18));
              });
              $('#random_app_salt').on('click', function (e) {
                $('input[name=app_salt]').val(randomString(32));
              });
            }
          });
        }

        //编辑
        function baredit(d) {
          kaige.form({
            url: "/sys.client/edit",
            data: { id: d.id },
            id: 'kaige',
            area: ['750px', '450px'],
            title: '<i class="layui-icon layui-icon-edit"></i> 编辑 - 客户端',
            tablelayid: 'pageTable',
            overflow: false,
            encode: 1,
            callbefore: function (layero, index) {
              $('#random_app_id').on('click', function (e) {
                $('input[name=app_id]').val(randomString(18));
              });
              $('#random_app_salt').on('click', function (e) {
                $('input[name=app_salt]').val(randomString(32));
              });
            },
          });
        }

        //删除
        function bardel(d) {
          layer.confirm('您确定删除吗？', {
            title: '<i class="layui-icon layui-icon-delete"></i> 删除确认',
            btn: ['确认', '取消']
          }, function () {
            $.post("/sys.client/del", { id: d.id }, function (res) {
              res.status && table.reload('pageTable');
              layer.msg(res.msg);
            });
          });
        };

      });
    });
  </script>
  <script type="text/html" id="dtrbar">
    <div class="layui-btn-group">
        <button class="layui-btn layui-btn-xs" lay-event="edit" title="编辑"><i class="layui-icon layui-icon-edit"></i></button>
        <button class="layui-btn layui-btn-xs" lay-event="del" title="删除"><i class="layui-icon layui-icon-delete"></i></button>
    </div>
  </script>
  <script type="text/html" id="dtoolbar">
    <div class="layui-form" lay-filter="searchform">
        <div class="layui-btn-group">
            <button type="button" class="layui-btn layui-btn-sm" lay-event="btn-add"><i class="layui-icon layui-icon-add-circle"></i> 添加</button>
        </div>
    </div>
  </script>
  <script type="text/html" id="kaige_form_html">
    <form class="layui-form layui-form-pane kaige-body-form" style="padding: 5px;" lay-filter="kaige_form_lay_filter">
      {{# if(d.id){ }}
      <input type="hidden" name="id" value="{{ d.id }}" />
      {{# } }}
      <div class="layui-form-item">
        <label class="layui-form-label fl-red">APPID</label>
        <div class="layui-input-inline" style="width: 320px;">
          <select name="type">
            <option value=""></option>
            <option value="1" {{ d.type !=2 ?'selected':'' }}>本地</option>
            <option value="2" {{ d.type ==2 ?'selected':'' }}>远程</option>
          </select>
        </div>
      </div>
      <div class="layui-form-item">
        <label class="layui-form-label fl-red">APPID</label>
        <div class="layui-input-inline" style="width: 320px;">
          <input name="app_id" value="{{ d.app_id || '' }}" lay-verify="required" lay-reqtext="请输入APPID"
            placeholder="APPID" class="layui-input" type="text">
        </div>
        <div class="layui-input-inline" style="width:100px;">
          <a class="layui-btn layui-btn-sm layui-bg-blue" href="javascript:;" id="random_app_id">随机</a>
        </div>
      </div>
      <div class="layui-form-item">
        <label class="layui-form-label fl-red">签名盐值</label>
        <div class="layui-input-inline" style="width: 320px;">
          <input name="app_salt" value="{{ d.app_salt || '' }}" lay-verify="required" lay-reqtext="请输入签名盐值"
            placeholder="签名盐值" class="layui-input" type="text">
        </div>
        <div class="layui-input-inline" style="width:100px;">
          <a class="layui-btn layui-btn-sm layui-bg-blue" href="javascript:;" id="random_app_salt">随机</a>
        </div>
      </div>
      <div class="layui-form-item">
        <label class="layui-form-label fl-red">应用名称</label>
        <div class="layui-input-inline">
          <input name="name" value="{{ d.name || '' }}" lay-verify="required" lay-reqtext="请输入应用名称"
            placeholder="应用名称" class="layui-input" type="text">
        </div>
        <label class="layui-form-label fl-red">服务器IP</label>
        <div class="layui-input-inline">
          <input name="reg_ip" value="{{ d.reg_ip || '' }}" placeholder="服务器IP" class="layui-input" type="text">
        </div>
      </div>
      <div class="layui-form-item">
        <label class="layui-form-label">状态</label>
        <div class="layui-input-inline border3">
          <input type="checkbox" name="status" lay-skin="switch" lay-text="启用|禁用" {{#  if(d.status ==1 ){ }} checked {{#  } }} />
        </div>
      </div>
      <div class="layui-form-item">
        <label class="layui-form-label fl-red">备注</label>
        <div class="layui-input-block">
          <textarea name="desc" lay-reqtext="请输入备注" placeholder="备注" class="layui-textarea"
            style="height: 150px;">{{ d.desc || '' }}</textarea>
        </div>
      </div>
      <div class="layui-form-item layui-hide">
        <button class="layui-hide" lay-submit="" id="kaige_form_btn_save" lay-filter="kaige_form_btn_save">保存数据</button>
      </div>
    </form>
  </script>
</body>

</html>